

from mmdet.apis import init_detector, inference_detector, show_result_pyplot


config_file = '../configs/rpn/rpn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
# checkpoint_file = '/home/deepin/Documents/openmmlab/mmdetection/tutorial_exps/latest.pth'
checkpoint_file = '../checkpoints/rpn_r50_fpn_1x_coco_20200218-5525fa2e.pth'

device = 'cuda:0'

# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)

# 查看 faster RCNN模型结构：
for name,module in model.named_children():
    print(name)
    [ print(F'    {n}') for n,_ in module.named_children() ]



# 推理 演示图像
# imgpath = r'/home/deepin/Documents/openmmlab/mmdetection/data/kitti_tiny/training/image_2/000000.jpeg'
imgpath = r'../demo/demo.jpg'
result=inference_detector(model, imgpath)
# print(result) ----查看 结果

# Let's plot the result 显示结果
# show_result_pyplot(model, imgpath, result, score_thr=0.3)

# 模型 内置的显示 提议框 ，top_k=100：提议框的数量
model.show_result(imgpath,result,top_k=100)


# 测试显示
# python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py  checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth

# 打印 cfg 文件 完整的 配置 信息 -- 并保存 到txt中
# python tools/misc/print_config.py configs/faster_rcnn/faster_rcnn_r50_caffe_c4_1x_coco.py > cfg.txt





